package com.zhiche.lisa.bms.controller.price;

import com.baomidou.mybatisplus.plugins.Page;
import com.zhiche.lisa.bms.dao.model.price.PriceFiRate;
import com.zhiche.lisa.bms.service.price.PriceFiRateService;
import com.zhiche.lisa.core.enums.CommonEnum;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * <p>
 * 财务系数设置 前端控制器
 * </p>
 *
 * @author qichao
 * @since 2018-08-31
 */
@RestController
@RequestMapping(value = "/priceFiRate")
@Api(value = "/priceFiRate", description = "财务系数设置", tags = {"财务系数设置"})
public class PriceFiRateController {
    private static final Logger LOGGER = LoggerFactory.getLogger(PriceFiRateController.class);

    @Autowired
    private PriceFiRateService iPriceFiRateService;

    /**
     * 财务系数列表
     *
     * @param page
     * @return
     */
    @PostMapping("/priceFiRateLine")
    @ApiOperation(value = "获取财务系数信息列表", notes = "获取财务系数信息列表", produces = MediaType.APPLICATION_JSON_VALUE, response
            = RestfulResponse.class)
    public RestfulResponse<Page<PriceFiRate>> priceFiRateLine(@RequestBody Page<PriceFiRate> page) {
        LOGGER.info("PriceFiRateController.priceFiRateLine（获取财务系数信息列表） params : {} ", page);
        RestfulResponse<Page<PriceFiRate>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            Page<PriceFiRate> pageVo = iPriceFiRateService.priceFiRateLinePage(page);
            result.setData(pageVo);
        } catch (BaseException e) {
            LOGGER.error("PriceFiRateController.priceFiRateLine error: {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("PriceController.priceFiRateLine error: {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    /**
     * 新增财务系数
     *
     * @param priceFiRate
     * @return
     */
    @PostMapping("/createPriceRate")
    @ApiOperation(value = "新增财务系数", notes = "新增财务系数", produces = MediaType.APPLICATION_JSON_VALUE, response
            = RestfulResponse.class)
    public RestfulResponse<String> createPriceRate(@RequestBody PriceFiRate priceFiRate) {
        LOGGER.info("PriceFiRateController.createPriceRate(新增财务系数) params:{}", priceFiRate);
        RestfulResponse<String> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            iPriceFiRateService.insertPriceRate(priceFiRate);
        } catch (BaseException e) {
            LOGGER.error("PriceFiRateController.createPriceRate error: {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("PriceFiRateController.createPriceRate error: {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        }
        return result;
    }
    /**
     * 根据承运商ID查询财务系数
     * @param lspId
     * @return
     */
    @PostMapping("/queeryPriceFiRateById")
    @ApiOperation(value = "根据承运商ID查询财务系数", notes = "根据承运商ID查询财务系数", produces = MediaType.APPLICATION_JSON_VALUE, response
            = RestfulResponse.class)
    public RestfulResponse<PriceFiRate> queeryPriceFiRateById(@RequestBody Long lspId) {
        LOGGER.info(" PriceController.queeryPriceFiRateById(查询财务系数) params:{}", lspId);
        RestfulResponse <PriceFiRate> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            PriceFiRate  priceFiRate = iPriceFiRateService.queryPriceFiRateById(lspId);
            result.setData(priceFiRate);
        } catch (BaseException e) {
            LOGGER.error("PriceController.selectPriceFiRateById error: {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("PriceController.selectPriceFiRateById error: {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        }
        return result;
    }
}
